package cn.baker.app.config;

import cn.baker.app.common.RabbitConstants;
import cn.baker.app.consumer.OrderMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

@Slf4j
@Configuration
public class RabbitConfig {

//    @Bean
//    public DirectExchange exchange1() {
//        return new DirectExchange(RabbitConstants.TEST_EXCHANGE);
//    }
//
//    @Bean
//    public Queue queue1() {
//        return new Queue(RabbitConstants.TEST_QUEUE,true, false, false, null);
//    }

//    @Bean
//    public Binding dlxBinding() {
//        return BindingBuilder
//                .bind(queue1())
//                .to(exchange1())
//                .with("");
//    }



    @Bean
    public SimpleMessageListenerContainer simpleMessageListenerContainer(ConnectionFactory connectionFactory, OrderMessageService orderMessageService) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
        container.setQueueNames(RabbitConstants.TEST_QUEUE);
        container.setExposeListenerChannel(true);
        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        container.setMessageListener(orderMessageService);
        return container;
    }

}